home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / yard.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  9KB  |  380 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   10 Yard Fight
  6.  
  7. L Taylor
  8. J Clegg
  9.  
  10.   Functions to emulate the video hardware of the machine.
  11.  
  12. ***************************************************************************/
  13.  
  14. #include "driver.h"
  15. #include "vidhrdw/generic.h"
  16.  
  17.  
  18. unsigned char *yard_scroll_x_low;
  19. unsigned char *yard_scroll_x_high;
  20. unsigned char *yard_scroll_y_low;
  21. unsigned char *yard_score_panel_disabled;
  22. static int flipscreen;
  23. static struct osd_bitmap *scroll_panel_bitmap;
  24.  
  25. #define SCROLL_PANEL_WIDTH  (14*4)
  26.  
  27. #define RADAR_PALETTE_BASE (256+16)
  28.  
  29. static struct rectangle panelvisiblearea =
  30. {
  31.     26*8, 32*8-1,
  32.     1*8, 31*8-1
  33. };
  34.  
  35. static struct rectangle panelvisibleareaflip =
  36. {
  37.     0*8, 6*8-1,
  38.     1*8, 31*8-1
  39. };
  40.  
  41.  
  42. /***************************************************************************
  43.  
  44.   Convert the color PROMs into a more useable format.
  45.  
  46.   10 Yard Fight has two 256x4 character palette PROMs, one 32x8 sprite
  47.   palette PROM, one 256x4 sprite color lookup table PROM, and two 256x4
  48.   radar palette PROMs.
  49.  
  50.   I don't know for sure how the palette PROMs are connected to the RGB
  51.   output, but it's probably something like this; note that RED and BLUE
  52.   are swapped wrt the usual configuration.
  53.  
  54.   bit 7 -- 220 ohm resistor  -- RED
  55.         -- 470 ohm resistor  -- RED
  56.         -- 220 ohm resistor  -- GREEN
  57.         -- 470 ohm resistor  -- GREEN
  58.         -- 1  kohm resistor  -- GREEN
  59.         -- 220 ohm resistor  -- BLUE
  60.         -- 470 ohm resistor  -- BLUE
  61.   bit 0 -- 1  kohm resistor  -- BLUE
  62.  
  63. ***************************************************************************/
  64. void yard_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  65. {
  66.     int i;
  67.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  68.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  69.  
  70.  
  71.     /* character palette */
  72.     for (i = 0;i < 256;i++)
  73.     {
  74.         int bit0,bit1,bit2;
  75.  
  76.  
  77.         /* red component */
  78.         bit0 = 0;
  79.         bit1 = (color_prom[256] >> 2) & 0x01;
  80.         bit2 = (color_prom[256] >> 3) & 0x01;
  81.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  82.         /* green component */
  83.         bit0 = (color_prom[0] >> 3) & 0x01;
  84.         bit1 = (color_prom[256] >> 0) & 0x01;
  85.         bit2 = (color_prom[256] >> 1) & 0x01;
  86.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  87.         /* blue component */
  88.         bit0 = (color_prom[0] >> 0) & 0x01;
  89.         bit1 = (color_prom[0] >> 1) & 0x01;
  90.         bit2 = (color_prom[0] >> 2) & 0x01;
  91.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  92.  
  93.         color_prom++;
  94.     }
  95.  
  96.     color_prom += 256;
  97.     /* color_prom now points to the beginning of the sprite palette */
  98.  
  99.  
  100.     /* sprite palette */
  101.     for (i = 0;i < 16;i++)
  102.     {
  103.         int bit0,bit1,bit2;
  104.  
  105.  
  106.         /* red component */
  107.         bit0 = 0;
  108.         bit1 = (*color_prom >> 6) & 0x01;
  109.         bit2 = (*color_prom >> 7) & 0x01;
  110.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  111.         /* green component */
  112.         bit0 = (*color_prom >> 3) & 0x01;
  113.         bit1 = (*color_prom >> 4) & 0x01;
  114.         bit2 = (*color_prom >> 5) & 0x01;
  115.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  116.         /* blue component */
  117.         bit0 = (*color_prom >> 0) & 0x01;
  118.         bit1 = (*color_prom >> 1) & 0x01;
  119.         bit2 = (*color_prom >> 2) & 0x01;
  120.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  121.  
  122.         color_prom++;
  123.     }
  124.  
  125.     color_prom += 16;
  126.     /* color_prom now points to the beginning of the sprite lookup table */
  127.  
  128.  
  129.     /* sprite lookup table */
  130.     for (i = 0;i < TOTAL_COLORS(1);i++)
  131.         COLOR(1,i) = 256 + (*(color_prom++) & 0x0f);
  132.  
  133.     /* color_prom now points to the beginning of the radar palette */
  134.  
  135.  
  136.     /* radar palette */
  137.     for (i = 0;i < 256;i++)
  138.     {
  139.         int bit0,bit1,bit2;
  140.  
  141.  
  142.         /* red component */
  143.         bit0 = 0;
  144.         bit1 = (color_prom[256] >> 2) & 0x01;
  145.         bit2 = (color_prom[256] >> 3) & 0x01;
  146.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  147.         /* green component */
  148.         bit0 = (color_prom[0] >> 3) & 0x01;
  149.         bit1 = (color_prom[256] >> 0) & 0x01;
  150.         bit2 = (color_prom[256] >> 1) & 0x01;
  151.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  152.         /* blue component */
  153.         bit0 = (color_prom[0] >> 0) & 0x01;
  154.         bit1 = (color_prom[0] >> 1) & 0x01;
  155.         bit2 = (color_prom[0] >> 2) & 0x01;
  156.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  157.  
  158.         color_prom++;
  159.     }
  160. }
  161.  
  162.  
  163.  
  164. /***************************************************************************
  165.  
  166.   Start the video hardware emulation.
  167.  
  168. ***************************************************************************/
  169. int yard_vh_start(void)
  170. {
  171.     if ((dirtybuffer = malloc(videoram_size)) == 0)
  172.         return 1;
  173.     memset(dirtybuffer,1,videoram_size);
  174.  
  175.     if ((tmpbitmap = osd_create_bitmap(Machine->drv->screen_width*2,Machine->drv->screen_height)) == 0)
  176.     {
  177.         free(dirtybuffer);
  178.         return 1;
  179.     }
  180.  
  181.     if ((scroll_panel_bitmap = osd_create_bitmap(SCROLL_PANEL_WIDTH,Machine->drv->screen_height)) == 0)
  182.     {
  183.         free(dirtybuffer);
  184.         osd_free_bitmap(tmpbitmap);
  185.         return 1;
  186.     }
  187.  
  188.     return 0;
  189. }
  190.  
  191.  
  192.  
  193. /***************************************************************************
  194.  
  195.   Stop the video hardware emulation.
  196.  
  197. ***************************************************************************/
  198. void yard_vh_stop(void)
  199. {
  200.     free(dirtybuffer);
  201.     osd_free_bitmap(tmpbitmap);
  202.     osd_free_bitmap(scroll_panel_bitmap);
  203. }
  204.  
  205.  
  206.  
  207. WRITE_HANDLER( yard_flipscreen_w )
  208. {
  209.     /* screen flip is handled both by software and hardware */
  210.     data ^= ~readinputport(4) & 1;
  211.  
  212.     if (flipscreen != (data & 1))
  213.     {
  214.         flipscreen = data & 1;
  215.         memset(dirtybuffer,1,videoram_size);
  216.     }
  217.  
  218.     coin_counter_w(0,data & 0x02);
  219.     coin_counter_w(1,data & 0x20);
  220. }
  221.  
  222.  
  223. WRITE_HANDLER( yard_scroll_panel_w )
  224. {
  225.     int sx,sy,i;
  226.  
  227.     sx = ( offset % 16 );
  228.     sy = ( offset / 16 );
  229.  
  230.     if (sx < 1 || sx > 14)  return;
  231.  
  232.     sx = 4 * (sx - 1);
  233.  
  234.     for (i = 0;i < 4;i++)
  235.     {
  236.         int col;
  237.  
  238.         col = (data >> i) & 0x11;
  239.         col = ((col >> 3) | col) & 3;
  240.  
  241.         plot_pixel(scroll_panel_bitmap, sx + i, sy, Machine->pens[RADAR_PALETTE_BASE + (sy & 0xfc) + col]);
  242.     }
  243. }
  244.  
  245.  
  246. /***************************************************************************
  247.  
  248.   Draw the game screen in the given osd_bitmap.
  249.   Do NOT call osd_update_display() from this function, it will be called by
  250.   the main emulation engine.
  251.  
  252. ***************************************************************************/
  253. void yard_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  254. {
  255.     int offs;
  256.  
  257.     /* for every character in the Video RAM, check if it has been modified */
  258.     /* since last time and update it accordingly. */
  259.     for (offs = videoram_size-2;offs >= 0;offs -= 2)
  260.     {
  261.         if (dirtybuffer[offs] || dirtybuffer[offs+1])
  262.         {
  263.             int sx,sy,flipx;
  264.  
  265.  
  266.             dirtybuffer[offs] = 0;
  267.             dirtybuffer[offs+1] = 0;
  268.  
  269.             sx = (offs/2) % 32;
  270.             sy = (offs/2) / 32;
  271.             flipx = videoram[offs+1] & 0x20;
  272.  
  273.             if (sy >= 32)
  274.             {
  275.                 sy -= 32;
  276.                 sx += 32;
  277.             }
  278.  
  279.             if (flipscreen)
  280.             {
  281.                 sx = 63 - sx;
  282.                 sy = 31 - sy;
  283.                 flipx = !flipx;
  284.             }
  285.  
  286.             drawgfx(tmpbitmap,Machine->gfx[0],
  287.                     videoram[offs] + ((videoram[offs+1] & 0xc0) << 2),
  288.                     videoram[offs+1] & 0x1f,
  289.                     flipx,flipscreen,
  290.                     8*sx,8*sy,
  291.                     0,TRANSPARENCY_NONE,0);
  292.         }
  293.     }
  294.  
  295.     /* copy the temporary bitmap to the screen */
  296.     {
  297.         int scroll_x,scroll_y;
  298.  
  299.         scroll_x = (*yard_scroll_x_high * 0x100) + *yard_scroll_x_low;
  300.  
  301.         if (flipscreen)
  302.         {
  303.             scroll_x += 256;
  304.             scroll_y = *yard_scroll_y_low ;
  305.         }
  306.         else
  307.         {
  308.             scroll_x = -scroll_x;
  309.             scroll_y = -*yard_scroll_y_low ;
  310.         }
  311.  
  312.         copyscrollbitmap(bitmap,tmpbitmap,1,&scroll_x,1,&scroll_y,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  313.     }
  314.  
  315.  
  316.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  317.     {
  318.         int code1,code2,bank,sx,sy1,sy2,flipx,flipy;
  319.  
  320.  
  321.         bank  = (spriteram[offs + 1] & 0x20) >> 5;
  322.         code1 =  spriteram[offs + 2] & 0xbf;
  323.         sx    =  spriteram[offs + 3];
  324.         sy1   =  241 - spriteram[offs];
  325.         flipx =  spriteram[offs + 1] & 0x40;
  326.         flipy =  spriteram[offs + 1] & 0x80;
  327.  
  328.         if (flipy)
  329.         {
  330.             code2 = code1;
  331.             code1 += 0x40;
  332.         }
  333.         else
  334.         {
  335.             code2 = code1 + 0x40;
  336.         }
  337.  
  338.         if (flipscreen)
  339.         {
  340.             flipx = !flipx;
  341.             flipy = !flipy;
  342.             sx  = 240 - sx;
  343.             sy2 = 224 - sy1;
  344.             sy1 = sy2 + 0x10;
  345.         }
  346.         else
  347.         {
  348.             sy2 = sy1 + 0x10;
  349.         }
  350.  
  351.         drawgfx(bitmap,Machine->gfx[1],
  352.                 code1 + 256 * bank,
  353.                 spriteram[offs + 1] & 0x1f,
  354.                 flipx,flipy,
  355.                 sx, sy1,
  356.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,256);
  357.  
  358.         drawgfx(bitmap,Machine->gfx[1],
  359.                 code2 + 256 * bank,
  360.                 spriteram[offs + 1] & 0x1f,
  361.                 flipx,flipy,
  362.                 sx, sy2,
  363.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,256);
  364.     }
  365.  
  366.  
  367.     /* draw the static bitmapped area to screen */
  368.     if (! *yard_score_panel_disabled)
  369.     {
  370.         int xpos;
  371.  
  372.         xpos = flipscreen ? Machine->drv->visible_area.min_x - 8 :
  373.                             Machine->drv->visible_area.max_x + 1 - SCROLL_PANEL_WIDTH;
  374.  
  375.         copybitmap(bitmap,scroll_panel_bitmap,flipscreen,flipscreen,
  376.                    xpos,0,
  377.                    flipscreen ? &panelvisibleareaflip : &panelvisiblearea,TRANSPARENCY_NONE,0);
  378.     }
  379. }
  380.